import router from '@/router/index'
import Vue from "vue";
import {getToken} from "@/utils/hook";
// 测试提交刷新服务器缓存
router.beforeEach(async (to, from, next) => {
    // 判断是否有标题
    if (to.meta.title) {
        document.title = to.meta.title;
    }
    if (!Vue.prototype.$pc) {
        // ? '/videoUpload' : '/videoMineH5'
    }
    /*如果是“登录”路由，不做操作*/
    if (to.path === '/login') {
        return next({replace: true})
    }
    //获取路由规则
    const routes = router.getRoutes();
    //映射出path
    const pathList = routes.map(item => item.path)
    //判断是否是非法路由,如果是跳转404页面
    if (pathList.indexOf(to.path) === -1) {
        next({path: "/notFindPage", replace: true})
    }
    const loginStatus = getToken()
    //判断是否登录成功
    if (loginStatus) {
        next()
    } else {
        next("/login")
        Vue.prototype.$message.warning("请先登录后，再操作！")
    }
})

router.afterEach(() => {
    // finish progress bar
    // NProgress.done()
})